<?php
require '../../../mainfile.php';
$image_root = XOOPS_MODULE_URL.'/scuttle/images/';

header('Content-Type: text/javascript');
?>

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
};

var deleted = false;

// 削除の確認
function deleteBookmark(ele, input){
	var confirmDelete = "<span><?php echo _MD_SC_AJAX_DELETE; ?> <a href=\"#\" onclick=\"deleteConfirmed(this, " + input + ", \'\'); return false;\"><?php echo _MD_SC_AJAX_YES; ?></a> - <a href=\"#\" onclick=\"deleteCancelled(this); return false;\"><?php echo _MD_SC_AJAX_NO; ?></a></span>";
	ele.style.display = 'none';
	ele.parentNode.innerHTML = ele.parentNode.innerHTML + confirmDelete;
}

// 削除キャンセル
function deleteCancelled(ele) {
	var del = previousElement(ele.parentNode);
	del.style.display = 'inline';
	ele.parentNode.parentNode.removeChild(ele.parentNode);
	return false;
}

// データの削除
function deleteConfirmed(ele, input, response) {
	if (deleted == false) {
		deleted = ele.parentNode.parentNode.parentNode.parentNode;
	}
	var post = deleted;
	post.className = 'xfolkentry deleted';
	if (response != '') {
		post.style.display = 'none';
		deleted = false;
	} else {
		loadXMLDoc('ajaxDelete.php?id=' + input);
		post.style.display = 'none';
	}
}


function previousElement(ele) {
	ele = ele.previousSibling;
	while (ele.nodeType != 1) {
		ele = ele.previousSibling;
	}
	return ele;
}


// HTTP通信の設定
var xmlhttp;
function loadXMLDoc(url) {
	// Native
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = processStateChange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	// ActiveX
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange = processStateChange;
			xmlhttp.open("GET", url, true);
			xmlhttp.send();
		}
	}
}

// 通信のリセット
function processStateChange() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		response = xmlhttp.responseXML.documentElement;
		method = response.getElementsByTagName('method')[0].firstChild.data;
		result = response.getElementsByTagName('result')[0].firstChild.data;
		eval(method + '(\'\', result)');
	}
}

